package 网络通信1;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.Scanner;

public class Clientn {
	public static void main(String[] args) throws Exception
	{
		Scanner sc=new Scanner(System.in);
		DatagramSocket socket=new DatagramSocket();
		//在多开客户端时，不能指定服务端的程序端口，否则会报错
		while(true) {
			System.out.println("请输入");
			String ss=sc.nextLine();
			if("exit".equals(ss)) {
				System.out.println("退出成功");
				socket.close();
				break;}
			byte[] buffer=ss.getBytes();
			DatagramPacket packet=new DatagramPacket(buffer,buffer.length,InetAddress.getLocalHost(),6666);
			socket.send(packet);
		}
	}
}